package no.ntnu.fp.gui.mainFrame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import no.ntnu.fp.client.Client;
import no.ntnu.fp.gui.EventDispatcher;
import no.ntnu.fp.gui.events.LogoutRequestedEvent;

@SuppressWarnings("serial")
public class MainFrameMenubar extends JMenuBar {
	
	public MainFrameMenubar(ActionListener quitListener) {
		JMenu fileMenu = new JMenu("Fil");
		
		JMenuItem logoutItmen = new JMenuItem("Log out", KeyEvent.VK_L);
		logoutItmen.addActionListener(new logOutAction());
		fileMenu.add(logoutItmen);
		fileMenu.addSeparator();
		
		JMenuItem quitItem = new JMenuItem("Quit", KeyEvent.VK_Q);
		quitItem.addActionListener(quitListener);
		fileMenu.add(quitItem);
		
		JMenu helpMenu = new JMenu("Help");
		JMenuItem about = new JMenuItem("About");
		about.addActionListener(new aboutAction());
		helpMenu.add(about);
		
		this.add(fileMenu);
		this.add(helpMenu);
	}
	private final class logOutAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			LogoutRequestedEvent evt = new LogoutRequestedEvent(this, Client.getEmployee());
			EventDispatcher.dispatchEvent(evt);
		}
	}
	private final class aboutAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			JOptionPane.showMessageDialog(null, "About this program...", 
					"About this program", JOptionPane.INFORMATION_MESSAGE);
		}
	}

}
